/*
 * @Author: 天羽落星辰
 * @Date: 2020-08-13 16:37:57
 * @LastEditors: 天羽落星辰
 * @LastEditTime: 2020-08-17 02:22:16
 * @Description: file content
 */
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'nozzle/empower/index' + location.search,
                    add_url: 'nozzle/empower/add',
                    edit_url: 'nozzle/empower/edit',
                    del_url: 'nozzle/empower/del',
                    multi_url: 'nozzle/empower/multi',
                    table: 'nozzle/empower',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.username', title: __('User_id')},
                        {field: 'company', title: __('Company')},
                        {field: 'apikey', title: __('Apikey')},
                        {field: 'everyday_number', title: __('Everyday_number')},
                        {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            
            bindevent: function () {
                require(['jquery-tagsinput'], function () {
                    //标签输入
                    var elem = "#c-white_list_ip";
                    var tags = $(elem);
                    tags.tagsInput({
                        width: 'auto',
                        defaultText: '输入后空格确认',
                        minInputWidth: 110,
                        height: '100px',
                        placeholderColor: '#999',
                        onChange: function (row) {
                            if (typeof callback === 'function') {

                            } else {
                                $(elem + "_addTag").focus();
                                $(elem + "_tag").trigger("blur.autocomplete").focus();
                            }
                        },
                        // autocomplete: {
                        //     url: 'cms/tags/autocomplete',
                        //     minChars: 1,
                        //     menuClass: 'autocomplete-tags'
                        // }
                    });
                });
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});